<template>
  <div v-loading="loading" class="beiji-container">
      <iframe v-if="show" :src="url" frameborder="0"></iframe>

      <stats-chart-empty v-if="error">
        {{ errorTxt }}
      </stats-chart-empty>
  </div>
</template>

<script>
/* api */
import { getBeiJiToken } from '@src/api/ReportApi.ts';
/* component */
import StatsChartEmpty from '@src/modules/report/common/StatsChartEmpty.vue';

export default {
    components: {
        StatsChartEmpty
    },
    data(){
        return {
            show: false,
            loading: true,
            error: false,
            url: '',
            errorTxt: '',
        }
    },
    created(){
        this.getToken();
    },
    methods: {
        async getToken(){
            try {
                const { code, data, msg } = await getBeiJiToken();
                this.loading = false;

                if(code !== 200){
                    this.errorTxt = msg;
                    this.error = true;
                    return;
                };

                this.url = data;
                this.show = true;
                console.log('北极数据URL', this.url);
            }catch(e){
                this.error = true;
                console.log('报表搜索引擎跳转', e);
            }
        }
    }
};
</script>

<style lang="scss" scoped>
body {
    background: none !important;
}
.beiji-container,iframe {
    width: 100%;
    height: 100%;
}
</style>
